project(i18n)

include_directories(include)

set(RUST_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/target")
if(CMAKE_BUILD_TYPE STREQUAL "Release")
  set(RUST_BUILD_MODE "release")
  set(RUST_BUILD_FLAG "--release")
else()
  set(RUST_BUILD_MODE "debug")
  set(RUST_BUILD_FLAG "")
endif()
set(RUST_I18N_LIB "${RUST_TARGET_DIR}/${RUST_BUILD_MODE}/libi18n.a")

dfhack_plugin(i18n
  i18n.cpp
  Game.cpp
  Offsets.cpp
  Strings.cpp
  LINK_LIBRARIES "${RUST_I18N_LIB}"
)

find_program(CARGO cargo REQUIRED)
add_custom_target(i18n_rust ALL
  BYPRODUCTS "${RUST_I18N_LIB}"
  COMMAND ${CARGO} build ${RUST_BUILD_FLAG} --target-dir="${RUST_TARGET_DIR}"
  WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  COMMENT "Building i18n Rust library in ${RUST_BUILD_MODE} mode"
)
